#include <REGX52.H>
#include <intrins.h>
unsigned char snum[]={0xf7,0xfb,0xfd,0xfe};
void Delay1ms(unsigned int xms)	//@11.0592MHz
{
	unsigned char i, j;
		while(xms--){
	_nop_();
	i = 2;
	j = 199;
	do
	{
		while (--j);
	} while (--i);
}
}
unsigned char Mstrixkey(){
	unsigned char keynumber=0;
	unsigned int i=0;
	for(i;i<4;i++){
		P1=0xff;
		P1=snum[i];
		if(P1_7==0){ Delay1ms(20);while(P1_7==0);Delay1ms(20);keynumber=1+i;}
		if(P1_6==0){ Delay1ms(20);while(P1_6==0);Delay1ms(20);keynumber=5+i;}
		if(P1_5==0){ Delay1ms(20);while(P1_5==0);Delay1ms(20);keynumber=9+i;}
		if(P1_4==0){ Delay1ms(20);while(P1_4==0);Delay1ms(20);keynumber=13+i;}
		if(keynumber)
		return keynumber;
	}
}